package DEMO;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * @author Lzm
 * @version 1.0
 */
public class test {
  private A a;
  @BeforeEach
  void setUp() {
    a = new A();
  }
  @Test
  void addPositiveNumbers() {
    int[] result = a.getF(10);
    int[] case1 = new int[]{0,1,1,2,3,5,8,13,21,34};
    try {
      assertArrayEquals(case1 , result, "数值满足");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
class A{
  List<Integer> list = new ArrayList<>();
  public A(){};
  public int[] getF(int n){
    list.add(0);
    list.add(1);
    backTracking(10,list);
    int[] result = new int[10];
    int index = 0;
    for (Integer integer : list) {
      result[index++] = integer;
    }
    return result;
  }
  public void backTracking(int n, List<Integer> list){
    if (list.size() >= n){
      return;
    }
    int number = list.get(list.size() - 1) + list.get(list.size() - 2);
    list.add(number);
    backTracking(n,list);
  }
}
